import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.Function;
import org.apache.spark.api.java.function.MapFunction;
import org.apache.spark.api.java.function.VoidFunction;
import org.apache.spark.sql.SparkSession;

import java.util.ArrayList;

/***
 * @author hunter.d
 * @qq 657270652
 * @wx haitao-duan
 * @date 2020/9/10
 **/
public class JavaSparkDemo {

    public static void main(String[] args) {

        SparkConf sparkConf = new SparkConf().setAppName("Spark WordCount Application (java)").setMaster("local");

        JavaSparkContext sc = new JavaSparkContext(sparkConf);
        ArrayList<String> lst = new ArrayList<>();
        lst.add("a");
        lst.add("b");
        lst.add("c");
        lst.add("d");
        JavaRDD<String> rdd = sc.parallelize(lst);
        Function f = new Function<String,String>(){
            @Override
            public String call(String value) throws Exception {
                return value.toUpperCase();
            }
        };
        rdd.map(f).foreach(new VoidFunction() {
            @Override
            public void call(Object o) throws Exception {
                System.out.println(o.toString());
            }
        });


    }
}
